package bigbrother.log.logentries;

import bigbrother.ParameterChecker;
import bigbrother.log.daylog.DayLogId;
import org.joda.time.DateTime;

/**
 * Common functionality for LogEntries.
 *
 * @author Hans Haggstrom
 */
public abstract class AbstractLogEntry
        implements LogEntry
{

    //======================================================================
    // Private Fields

    private final DateTime myTimeStamp;
    private final String myNick;
    private final DayLogId myDayLogId;

    //======================================================================
    // Public Methods

    //----------------------------------------------------------------------
    // Comparable Implementation

    public final int compareTo( final LogEntry otherEntry )
    {
        return myTimeStamp.compareTo( otherEntry.getTimeStamp() );
    }

    //----------------------------------------------------------------------
    // LogEntry Implementation

    public DateTime getTimeStamp()
    {
        return myTimeStamp;
    }


    public String getChannel()
    {
        return myDayLogId.getChannelName();
    }


    public final String getNick()
    {
        return myNick;
    }


    public DayLogId getDayLogId()
    {
        return myDayLogId;
    }

    //======================================================================
    // Protected Methods

    //----------------------------------------------------------------------
    // Protected Constructors

    /**
     * @param timeStamp the time that this message was logged on.
     * @param nick      nickname that this log entry is associated with.
     * @param channel   the channel the message appeared in, or the nick name of the other person if it was a private
     *                  conversation.
     */
    protected AbstractLogEntry( final DateTime timeStamp, final String nick, final String channel )
    {
        ParameterChecker.checkNotNull( timeStamp, "timeStamp" );
        ParameterChecker.checkNotNull( nick, "nick" );
        ParameterChecker.checkNotNull( channel, "channel" );

        myTimeStamp = timeStamp;
        myNick = nick;
        myDayLogId = new DayLogId( channel, myTimeStamp.toDateMidnight() );
    }

}
